<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>添加</title>
	<!-- 引入样式 -->
	<link rel="stylesheet" href="https://unpkg.com/element-ui@2.6.3/lib/theme-chalk/index.css">

</head>
<body>
<el-form :model="user" >
	<div id="app">
		<el-input style="margin: 20px 0" v-model="user.userName" type="text"  placeholder="账号"></el-input>
		<el-input style="margin: 20px 0" v-model="user.passWord"  type="password" placeholder="密码"></el-input>
		<div style="margin: 20px 0">
			<el-button type="primary" @click="onSubmit('user')" >注册</el-button>
		</div>
	</div>
</el-form>
</body>
<script src="https://cdn.bootcss.com/vue-resource/1.5.1/vue-resource.min.js"></script>
<script src="https://unpkg.com/vue/dist/vue.js"></script>
<script src="https://unpkg.com/element-ui/lib/index.js"></script>
<script>
	var Main = {
		data() {
			return {
				user: {
					userName: '',
					passWord: ''
				},
			};
		},
		methods: {

		},
		methods: {
			onSubmit(formName) {
				//打印日志
				console.log(this.user.passWord);
				console.log(this.user.userName);
				//post请求  发送到账号密码信息到login方法
				this.$http.post('/halo/register', {
					'userName': this.user.userName,
					'passWord': this.user.passWord
				}, {
					/*
                    * 启用该选项后，请求会以application/x-www-form-urlencoded作为MIME type，就像普通的HTML表单一样。form形式传给后台，而非json形式。
                    * */
					emulateJSON: true
				}).then(function(res) {
					//设置状态
					if(res.data.code == '0') {
						this.$message({
							message: "操作成功",
							type: 'success'
						});
					} else {
						this.$message({
							message: res.body.message,
							type: 'error'
						})
						return;
					}
				})
			},
		}
	}
	var Ctor = Vue.extend(Main)
	new Ctor().$mount('#app')
</script>
</html>